#include "System.h"

using namespace std;

void System::deleteplaceGujia()
{
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 20, "删除地点");
    IMAGE retn;
    loadimage(&retn, "./返回.png", 16, 29);
    putimage(25, 27, &retn);

    //下栏图标设置
    IMAGE img;
    loadimage(&img, "./景点.png", 44, 44);
    putimage(166, 748, &img);
    setlinecolor(RGB(15, 19, 174));
    line(27, 774, 145, 774);
    line(230, 774, 348, 774);

    //按钮设置
BasicButton btn1(31, 228, 314, 64, 10, "删除普通地点");
btn1.setbtncl(56, 164, 254);
btn1.settext(255, 255, 255, 32, 91, 241);
btn1.show();

BasicButton btn2(31, 316, 314, 64, 10, "删除十字路口点");
btn2.setbtncl(56, 164, 254);
btn2.settext(255, 255, 255, 32, 75, 329);
btn2.show();

BasicButton btn3(31, 404, 314, 64, 10, "删除景点");
btn3.setbtncl(56, 164, 254);
btn3.settext(255, 255, 255, 32, 123, 417);
btn3.show();

BasicButton btn4(113, 492, 152, 64, 10, "返回");
btn4.setbtncl(217, 217, 217);
btn4.settext(101, 101, 101, 32, 156, 505);
btn4.show();

    int choose = 0;
    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            if (m_msg.x >= 0 && m_msg.x <= 68 && m_msg.y >= 0 && m_msg.y <= 83) {
                if (m_msg.message == WM_LBUTTONDOWN) { //点击返回键，回到主页功能骨架
                    return;
                }
            }

            btn1.setmsg(m_msg);
            if (btn1.isCliked()) { //点击了删除普通地点按钮
                choose = 1;
                break; //跳出循环
            }

            btn2.setmsg(m_msg);
            if (btn2.isCliked()) { //点击了删除十字路口点按钮
                choose = 2;
                break; //跳出循环
            }

            btn3.setmsg(m_msg);
            if (btn3.isCliked()) { //点击了删除景点按钮
                choose = 3;
                break; //跳出循环
            }

            btn4.setmsg(m_msg);
            if (btn4.isCliked()) { //点击了返回按钮，回到主页功能骨架
                return;
            }

        }
    }
    switch (choose) {
    case 1:
        deleteOrdinaryDot();//删除普通点
        break;
    case 2:
        deleteCrossroad();//删除十字路口点
        break;
    case 3:
        deletePlace();//删除景点
        break;
    default:
        break;
    }
}

//删除普通点
void System::deleteOrdinaryDot()
{
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(84, 20, "删除普通地点");
    IMAGE retn;
    loadimage(&retn, "./返回.png", 16, 29);
    putimage(25, 27, &retn);

    //按钮设置
    BasicButton btn1(110, 407, 152, 64, 10, "删除");
    btn1.setbtncl(56, 164, 254);
    btn1.settext(255, 255, 255, 32, 154, 420);
    btn1.show();

    BasicButton btn2(110, 515, 152, 64, 10, "返回");
    btn2.setbtncl(217, 217, 217);
    btn2.settext(101, 101, 101, 32, 153, 528);
    btn2.show();

    //输入框设置
    settextcolor(RGB(0, 0, 0));
    settextstyle(32, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(31, 222, "地点坐标：");

    Textbox tb1(31, 281, 314, 57, "", 5);
    tb1.settitle("请输入待删除地点坐标,输入格式：坐标x 坐标y（x和y用空格分开）：");
    tb1.show();

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            if (m_msg.x >= 0 && m_msg.x <= 68 && m_msg.y >= 0 && m_msg.y <= 83) {
                if (m_msg.message == WM_LBUTTONDOWN) { //点击返回键，回到主页功能骨架
                    return;
                }
            }

            btn1.setmsg(m_msg);
            if (btn1.isCliked()) { //点击了删除按钮
                string pos = tb1.gettext();
                stringstream ss(pos);
                int x = 0; int y = 0;
                ss >> x; ss >> y;
                DeleteDot(x, y);
                break; //删除完成则跳出循环
            }

            btn2.setmsg(m_msg);
            if (btn2.isCliked()) { //点击了返回按钮，回到主页功能骨架
                return;
            }

            tb1.setmsg(m_msg); //地点名称输入
            if (tb1.isCliked()) {
                tb1.updatetext(0);
            }
        }
    }
    //添加完成则跳出循环，并给出成功提示
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(84, 20, "删除普通地点");

    //下栏图标设置
    IMAGE img;
    loadimage(&img, "./景点.png", 44, 44);
    putimage(166, 748, &img);
    setlinecolor(RGB(15, 19, 174));
    line(27, 774, 145, 774);
    line(230, 774, 348, 774);

    //按钮设置
    BasicButton btn(110, 545, 152, 64, 10, "确定");
    btn.setbtncl(96, 218, 255);
    btn.settext(0, 72, 125, 32, 153, 559);
    btn.show();

    IMAGE success;
    loadimage(&success, "./成功.png", 174, 174);
    putimage(101, 232, &success);
    settextcolor(RGB(0, 0, 0));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 431, "删除成功！");

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            btn.setmsg(m_msg);
            if (btn.isCliked()) { //点击了确定按钮，回到主页功能骨架
                return;
            }
        }
    }
}


//删除十字路口
void System::deleteCrossroad()
{
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(84, 20, "删除十字路口");
    IMAGE retn;
    loadimage(&retn, "./返回.png", 16, 29);
    putimage(25, 27, &retn);

    //按钮设置
    BasicButton btn1(110, 407, 152, 64, 10, "删除");
    btn1.setbtncl(56, 164, 254);
    btn1.settext(255, 255, 255, 32, 154, 420);
    btn1.show();

    BasicButton btn2(110, 515, 152, 64, 10, "返回");
    btn2.setbtncl(217, 217, 217);
    btn2.settext(101, 101, 101, 32, 153, 528);
    btn2.show();

    //输入框设置
    settextcolor(RGB(0, 0, 0));
    settextstyle(32, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(31, 222, "地点坐标：");

    Textbox tb1(31, 281, 314, 57, "", 5);
    tb1.settitle("请输入待删除地点坐标,输入格式：坐标x 坐标y（x和y用空格分开）：");
    tb1.show();

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            if (m_msg.x >= 0 && m_msg.x <= 68 && m_msg.y >= 0 && m_msg.y <= 83) {
                if (m_msg.message == WM_LBUTTONDOWN) { //点击返回键，回到主页功能骨架
                    return;
                }
            }

            btn1.setmsg(m_msg);
            if (btn1.isCliked()) { //点击了删除按钮
                string pos = tb1.gettext();
                stringstream ss(pos);
                int x = 0; int y = 0;
                ss >> x; ss >> y;
                DeleteDot(x, y);
                break; //删除完成则跳出循环
            }

            btn2.setmsg(m_msg);
            if (btn2.isCliked()) { //点击了返回按钮，回到主页功能骨架
                return;
            }

            tb1.setmsg(m_msg); //地点名称输入
            if (tb1.isCliked()) {
                tb1.updatetext(0);
            }
        }
    }
    //添加完成则跳出循环，并给出成功提示
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(84, 20, "删除十字路口");

    //下栏图标设置
    IMAGE img;
    loadimage(&img, "./景点.png", 44, 44);
    putimage(166, 748, &img);
    setlinecolor(RGB(15, 19, 174));
    line(27, 774, 145, 774);
    line(230, 774, 348, 774);

    //按钮设置
    BasicButton btn(110, 545, 152, 64, 10, "确定");
    btn.setbtncl(96, 218, 255);
    btn.settext(0, 72, 125, 32, 153, 559);
    btn.show();

    IMAGE success;
    loadimage(&success, "./成功.png", 174, 174);
    putimage(101, 232, &success);
    settextcolor(RGB(0, 0, 0));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 431, "删除成功！");

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            btn.setmsg(m_msg);
            if (btn.isCliked()) { //点击了确定按钮，回到主页功能骨架
                return;
            }
        }
    }
}


//删除景点页面
void System::deletePlace()
{
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 20, "删除景点");
    IMAGE retn;
    loadimage(&retn, "./返回.png", 16, 29);
    putimage(25, 27, &retn);

    //按钮设置
    BasicButton btn1(110, 407, 152, 64, 10, "删除");
    btn1.setbtncl(56, 164, 254);
    btn1.settext(255, 255, 255, 32, 154, 420);
    btn1.show();

    BasicButton btn2(110, 515, 152, 64, 10, "返回");
    btn2.setbtncl(217, 217, 217);
    btn2.settext(101, 101, 101, 32, 153, 528);
    btn2.show();

    //输入框设置
    settextcolor(RGB(0, 0, 0));
    settextstyle(32, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(31, 222, "景点名称：");

    Textbox tb1(31, 281, 314, 57, "", 5);
    tb1.settitle("请输入待删除的景点名称：");
    tb1.show();

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            if (m_msg.x >= 0 && m_msg.x <= 68 && m_msg.y >= 0 && m_msg.y <= 83) {
                if (m_msg.message == WM_LBUTTONDOWN) { //点击返回键，回到主页功能骨架
                    return;
                }
            }

            btn1.setmsg(m_msg);
            if (btn1.isCliked()) { //点击了删除按钮
                string plname = tb1.gettext();
                auto it = SceneryKu.find(plname); //通过名字找到对应景点
                DeleteDot(it->second.Getx(), it->second.Gety());
                //删除景点功能函数
                break; //删除完成则跳出循环
            }

            btn2.setmsg(m_msg);
            if (btn2.isCliked()) { //点击了返回按钮，回到主页功能骨架
                return;
            }

            tb1.setmsg(m_msg); //景点名称输入
            if (tb1.isCliked()) {
                tb1.updatetext(0);
            }
        }
    }
    //添加完成则跳出循环，并给出成功提示
    setbkcolor(RGB(255, 255, 255));
    cleardevice();
    //顶栏设置
    setfillcolor(RGB(130, 226, 255));
    fillroundrect(0, 0, 375, 83, 0, 0);
    settextcolor(RGB(0, 72, 125));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 20, "删除景点");

    //下栏图标设置
    IMAGE img;
    loadimage(&img, "./景点.png", 44, 44);
    putimage(166, 748, &img);
    setlinecolor(RGB(15, 19, 174));
    line(27, 774, 145, 774);
    line(230, 774, 348, 774);

    //按钮设置
    BasicButton btn(110, 545, 152, 64, 10, "确定");
    btn.setbtncl(96, 218, 255);
    btn.settext(0, 72, 125, 32, 153, 559);
    btn.show();

    IMAGE success;
    loadimage(&success, "./成功.png", 174, 174);
    putimage(101, 232, &success);
    settextcolor(RGB(0, 0, 0));
    settextstyle(36, 0, "黑体");//设置文本大小，垂直压缩，字体
    setbkmode(TRANSPARENT);//去除文字背景
    outtextxy(113, 431, "删除成功！");

    //持续循环直到获取鼠标点击按钮的信号
    while (1) {
        if (Window::havemsg()) {
            m_msg = Window::getmsg();
            btn.setmsg(m_msg);
            if (btn.isCliked()) { //点击了确定按钮，回到主页功能骨架
                return;
            }
        }
    }
}